<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function index() {
        //$peticion = $this->add();
        //$this->process('usu.add', $peticion);
        
        //$peticion = $this->delete();
        //$this->process('usu.del', $peticion);

        //$peticion = $this->update();
        //$this->process('usu.upd', $peticion);
        
        //$peticion = $this->select();
        //$this->process('usu.sel', $peticion);
        $this->load->view('index');
    }

    function select(){
        $request = array(
            array(
                // Param 0
                array(
                    'library' => 'usuario',
                    'method' => 'add'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'where' => 'usu_idusuario in (31, 32)'
                ),
                'struct'
            )
        );
        return $request;
    }    
    
    function delete(){
        $request = array(
            array(
                // Param 0
                array(
                    'library' => 'usuario',
                    'method' => 'add'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'where' => 'usu_idusuario = 29'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'where' => 'usu_idusuario = 30'
                ),
                'struct'
            )
        );
        return $request;
    }    
    
    function update(){
        $request = array(
            array(
                // Param 0
                array(
                    'library' => 'usuario',
                    'method' => 'add'
                ),
                'struct'
            ),
            array(
                array(
                    'usu_nombre' => 'pruebaupdate1',
                    'where' => 'usu_idusuario = 31'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'usu_nombre' => 'pruebaupsdfs2',
                    'where' => 'usu_idusuario = 32'
                ),
                'struct'
            )
        );
        return $request;
    }

    function add(){
        $request = array(
            array(
                // Param 0
                array(
                    'library' => 'usuario',
                    'method' => 'add'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'usu_nombre' => 'pepbeer',
                    'usu_email' => 'pepmahou@hotmail.com',
                    'usu_password' => 'pepito'
                ),
                'struct'
            ),
            array(
                // Param 1
                array(
                    'usu_nombre' => 'pepmanel',
                    'usu_email' => 'pepbeer@hotmail.com',
                    'usu_password' => 'pepmanel1234'
                ),
                'struct'
            )
        );
        return $request;
    }

    function process($metodo = '', $request = null){
        $this->load->helper('url');
        $server_url = 'http://127.0.0.1/gestorweb/';

        $this->load->library('xmlrpc');
        $this->xmlrpc->server($server_url, 80);
        $this->xmlrpc->method($metodo);
        $this->xmlrpc->set_debug($this->config->item('debug_xmlrpc'));

        $this->xmlrpc->request($request);

        if (!$this->xmlrpc->send_request()) {
            echo $this->xmlrpc->display_error();
        } else {
            echo '<pre>';
            print_r($this->xmlrpc->display_response());
            echo '</pre>';
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */